#include <iostream>
#include <cstdio>

using namespace std;

typedef long long LL;

LL a, b, p;
//a一直加b次
	//a=a
	//2a=a+a
	//4a=2a+2a
	//8a=4a+4a
	//16a=8a+8a
//快速乘的模版
LL qmul(LL a, LL b, LL p)
{
	LL ret = 0;
	while(b)
	{
		if(b & 1) ret = (ret + a) % p;
		a = (a + a) % p;
		b >>= 1;
	}

	return ret;
}

//a一直加b次
//a=a
//2a=a+a
//4a=2a+2a
//8a=4a+4a
//16a=8a+8a

int main()
{
	cin >> a >> b >> p;
	
	cout << qmul(a, b, p) << endl;

	return 0;
}

